
<!DOCTYPE html>
<html lang="zh-cn">
    <head>
        <meta charset="utf-8">
        <title>浏览页面</title>
        <link rel="stylesheet" href="/app/admin/component/pear/css/pear.css" />
        <link rel="stylesheet" href="/app/admin/admin/css/reset.css" />
        <style>
            audio {
                width: 300px;
                height: 40px;
            }
        </style>
    </head>
    <body class="pear-container">
    
        <!-- 顶部查询表单 -->
        <div class="layui-card">
            <div class="layui-card-body">
                <form class="layui-form top-search-from">
                    <div class="layui-form-item">
                        <label class="layui-form-label">用户编号</label>
                        <div class="layui-input-block">
                            <div class="layui-input-block">
                                <input type="text" autocomplete="off" name="user_sn" class="layui-input">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">昵称</label>
                        <div class="layui-input-block">
                            <div class="layui-input-block">
                                <input type="hidden" autocomplete="off" name="nickname[]" value="like" class="layui-input inline-block">
                                <input type="text" autocomplete="off" name="nickname[]" class="layui-input">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">上级ID</label>
                        <div class="layui-input-block">
                            <div class="layui-input-block">
                                <input type="text" autocomplete="off" name="parentid" class="layui-input">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">邀请码</label>
                        <div class="layui-input-block">
                            <div class="layui-input-block">
                                <input type="text" autocomplete="off" name="invit_code" class="layui-input">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">手机号</label>
                        <div class="layui-input-block">
                            <div class="layui-input-block">
                                <input type="text" autocomplete="off" name="mobile" class="layui-input">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">是会员</label>
                        <div class="layui-input-block">
                            <div name="is_vip" id="is_vip" value="" ></div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">代理级别</label>
                        <div class="layui-input-block">
                            <div name="agent_level" id="agent_level" value="" ></div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">巨量推广</label>
                        <div class="layui-input-block">
                            <div name="callback_param" id="callback_param" value="" ></div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">注册时间</label>
                        <div class="layui-input-block">
                            <div class="layui-input-block" id="created_at">
                                <input type="text" autocomplete="off" name="created_at[]" id="created_at-date-start" class="layui-input inline-block" placeholder="开始时间">
                                -
                                <input type="text" autocomplete="off" name="created_at[]" id="created_at-date-end" class="layui-input inline-block" placeholder="结束时间">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item layui-inline">
                        <label class="layui-form-label"></label>
                        <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="table-query">
                            <i class="layui-icon layui-icon-search"></i>查询
                        </button>
                        <button type="reset" class="pear-btn pear-btn-md" lay-submit lay-filter="table-reset">
                            <i class="layui-icon layui-icon-refresh"></i>重置
                        </button>
                    </div>
                    <div class="toggle-btn">
                        <a class="layui-hide">展开<i class="layui-icon layui-icon-down"></i></a>
                        <a class="layui-hide">收起<i class="layui-icon layui-icon-up"></i></a>
                    </div>
                </form>
            </div>
        </div>
        
        <!-- 数据表格 -->
        <div class="layui-card">
            <div class="layui-card-body">
                <table id="data-table" lay-filter="data-table"></table>
            </div>
        </div>

        <!-- 表格顶部工具栏 -->
        <script type="text/html" id="table-toolbar">
            <!--<button class="pear-btn pear-btn-primary pear-btn-md" lay-event="add" permission="app.admin.user.index.insert">-->
                <!--<i class="layui-icon layui-icon-add-1"></i>新增-->
            <!--</button>-->
        </script>

        <!-- 表格行工具栏 -->
        <script type="text/html" id="table-bar">
            <button class="pear-btn pear-btn-xs tool-btn" lay-event="edit" permission="app.admin.user.index.update">用户设置</button>
            <button class="pear-btn pear-btn-xs tool-btn" lay-event="works" permission="app.admin.user.works.select">我的作品</button>

        </script>

        <script src="/app/admin/component/layui/layui.js?v=2.8.12"></script>
        <script src="/app/admin/component/pear/pear.js"></script>
        <script src="/app/admin/admin/js/permission.js"></script>
        <script src="/app/admin/admin/js/common.js"></script>
        <script src="/app/admin/admin/js/functions.js"></script>
        <script src="/app/admin/admin/js/md5.js"></script>
        
        <script>

            // 相关常量
            const PRIMARY_KEY = "userid";
            const SELECT_API = "/app/admin/user/index/select";
            const UPDATE_API = "/app/admin/user/index/update";
            const UPDATE_URL = "/app/admin/user/index/update";
            const FLOW_URL = "/app/admin/user/point/index";
            const WORKS_URL = "/app/admin/user/works/index";

            let where = {};
            let isHide =false;

            // 字段 添加时间 created_at
            layui.use(["laydate"], function() {
                layui.laydate.render({
                    elem: "#created_at",
                    range: ["#created_at-date-start", "#created_at-date-end"],
                    type: "datetime",
                    mark: date_today_mark,
                });
            })

            // 字段 状态 is_vip
            layui.use(["jquery", "xmSelect"], function() {
                let value = layui.$("#is_vip").attr("value");
                let initValue = value ? value.split(",") : [];
                layui.xmSelect.render({
                    el: "#is_vip",
                    name: "is_vip",
                    filterable: true,
                    initValue: initValue,
                    data: [{"value":"1","name":"是"}],
                    model: {"icon":"hidden","label":{"type":"text"}},
                    clickClose: true,
                    radio: true
                })
            });

            // 字段 状态 status
            layui.use(["jquery", "xmSelect"], function() {
                let value = layui.$("#agent_level").attr("value");
                let initValue = value ? value.split(",") : [];
                layui.xmSelect.render({
                    el: "#agent_level",
                    name: "agent_level",
                    filterable: true,
                    initValue: initValue,
                    data: [{"value":"1","name":"V1"},{"value":"2","name":"V2"},{"value":"3","name":"V3"}],
                    model: {"icon":"hidden","label":{"type":"text"}},
                    clickClose: true,
                    radio: true
                })
            });

            // 字段 巨量推广 callback_param
            layui.use(["jquery", "xmSelect"], function() {
                let value = layui.$("#callback_param").attr("value");
                let initValue = value ? value.split(",") : [];
                layui.xmSelect.render({
                    el: "#callback_param",
                    name: "callback_param",
                    filterable: true,
                    initValue: initValue,
                    data: [{"value":"yes","name":"是"},{"value":"no","name":"否"}],
                    model: {"icon":"hidden","label":{"type":"text"}},
                    clickClose: true,
                    radio: true
                })
            });

            // 表格渲染
            layui.use(["table", "form", "common", "popup", "util"], function() {
                let table = layui.table;
                let form = layui.form;
                $ = layui.$;
                let common = layui.common;
                let util = layui.util;
                
				// 表头参数
				let cols = [
					{
						title: "ID",align: "center", field: "user_sn",width:120,sort:true,
					},{
						title: "昵称",align: "center", field: "nickname",width:180,sort:true,
					},{
						title: "手机号",align: "center", field: "mobile",width:120
					},{
                        title: "头像",align: "center", field: "headimgurl",width:120, templet: function (d) {
                            return '<img src="'+encodeURI(d['headimgurl'])+'" style="max-width:32px;max-height:32px;" alt="" />'
                        }
                    },{
                        title: "代理级别",align: "center", field: "agent_level",width:110,sort:true, templet: function (d) {
                            if(d.agent_level=='3'){
                                return '<span style="color: #0e84ec;">V'+d.agent_level+'</span>';
                            }else if(d.agent_level=='2'){
                                return '<span style="color: #8b11da;">V'+d.agent_level+'</span>';
                            }else{
                                return '<span style="color: #f5b61e;">V'+d.agent_level+'</span>';;
                            }
                        }
                    },{
                        title: "巨量推广",align: "center", field: "callback_param",width:100,sort:true, templet: function (d) {
                            if(d.callback_param!=''){
                                return '<span style="color: #0e84ec;">是</span>';
                            }else {
                                return '否';
                            }
                        }
                    },{
                        title: "是否VIP",align: "center", field: "is_vip",width:100,sort:true, templet: function (d) {
                            if(d.is_vip==1){
                                return '<span style="color: #0e84ec;">VIP</span>';
                            }else if(d.is_vip==2){
                                return '<span style="color: #8b11da;">体验VIP</span>';
                            }else {
                                return '否';
                            }
                        }
                    },{
                        title: "VIP有效期",align: "center", field: "vip_expire_time",width:150,sort:true,
                    },{
                        title: "会员点数",align: "center", field: "vip_points",width:120, templet: function (d) {
                            if(d.is_vip==1){
                                return d.vip_points+' <a href="javascript:flow(\''+d.user_sn+'\',1);">明细</a> ';
                            }else if(d.is_vip==2){
                                return d.vip_points+' <a href="javascript:flow(\''+d.user_sn+'\',3);">明细</a> ';
                            }else{
                                return d.vip_points+' <a href="javascript:flow(\''+d.user_sn+'\',1);">明细</a> ';
                            }
                        }
                    },{
                        title: "永久点数",align: "center", field: "buy_points",width:120, templet: function (d) {
                            return d.buy_points+' <a href="javascript:flow(\''+d.user_sn+'\',2);">明细</a> ';
                        }
                    },{
                        title: "累计收益",align: "center", field: "total_income_amount",width:120,
                    },{
                        title: "可提现金额",align: "center", field: "can_withdraw_amount",width:120,
                    },{
                        title: "已提现金额",align: "center", field: "withdraw_amount",width:120,
                    },{
                        title: "邀请人数",align: "center", field: "invit_user_nums",width:110,
                    },{
                        title: "推文比例",align: "center", field: "talent_rate",width:150,
                    },{
                        title: "邀请比例",align: "center", field: "income_rate",width:110,
                    }
                    // ,{
                    //     title: "奖励方案",align: "center", field: "reward_plan_name",width:120,
                    // }
                    ,{
                        title: "邀请码",align: "center", field: "invit_code",width:100,
                    },{
                        title: "邀请二维码",align: "center", field: "qrcode_image", width:120,templet: function (d) {
                            return '<img src="'+encodeURI(d['qrcode_image'])+'" style="max-width:32px;max-height:32px;" alt="" />'
                        }
                    },{
                        title: "推荐用户ID",align: "center", field: "invit_user_sn", width:120
                    },{
                        title: "推荐用户昵称",align: "center", field: "invit_user_nickname", width:120
                    },{
                        title: "注册时间",align: "center", field: "created_at",width: 180,sort:true,
                    },{
						title: "操作", toolbar: "#table-bar", align: "center", fixed: "right", width: 180,
					}
				];
				
				// 渲染表格
				table.render({
				    elem: "#data-table",
				    url: SELECT_API,
				    page: true,
                    headers: get_header(where),
				    cols: [cols],
				    skin: "line",
				    size: "lg",
				    toolbar: "#table-toolbar",
				    autoSort: false,
				    defaultToolbar: [{
				        title: "刷新",
				        layEvent: "refresh",
				        icon: "layui-icon-refresh",
				    }, "filter", "print", "exports"],
				    done: function () {
				        layer.photos({photos: 'div[lay-id="data-table"]', anim: 5});
				    }
				});
				
				// 获取表格中下拉或树形组件数据
				let apiResults = {};
				apiResults["position"] = [];
                // 编辑或删除行事件
                table.on("tool(data-table)", function(obj) {
                    if (obj.event === "edit") {
                        edit(obj);
                    }else if (obj.event === "works") {
                        works(obj);
                    }
                });

                // 表格顶部工具栏事件
                table.on("toolbar(data-table)", function(obj) {
                    if (obj.event === "add") {
                        add();
                    } else if (obj.event === "refresh") {
                        refreshTable();
                    }
                });

                // 表格顶部搜索事件
                form.on("submit(table-query)", function(data) {
                    where = searchWhere(data.field);
                    table.reload("data-table", {
                        page: {
                            curr: 1
                        },
                        where: where,
                        headers: get_header(where)
                    })
                    return false;
                });
                
                // 表格顶部搜索重置事件
                form.on("submit(table-reset)", function(data) {
                    where = {};
                    table.reload("data-table", {
                        where: where,
                        headers: get_header(where)
                    })
                });
                
                // 字段允许为空
                form.verify({
                    phone: [/(^$)|^1\d{10}$/, "请输入正确的手机号"],
                    email: [/(^$)|^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/, "邮箱格式不正确"],
                    url: [/(^$)|(^#)|(^http(s*):\/\/[^\s]+\.[^\s]+)/, "链接格式不正确"],
                    number: [/(^$)|^\d+$/,'只能填写数字'],
                    date: [/(^$)|^(\d{4})[-\/](\d{1}|0\d{1}|1[0-2])([-\/](\d{1}|0\d{1}|[1-2][0-9]|3[0-1]))*$/, "日期格式不正确"],
                    identity: [/(^$)|(^\d{15}$)|(^\d{17}(x|X|\d)$)/, "请输入正确的身份证号"]
                });

                // 表格排序事件
                table.on("sort(data-table)", function(obj){
                    where.field=obj.field;
                    where.order=obj.type;
                    table.reload("data-table", {
                        initSort: obj,
                        scrollPos: "fixed",
                        where: where,
                        headers: get_header(where)
                    });
                });

                // 表格编辑数据
                let edit = function(obj) {
                    let value = obj.data[PRIMARY_KEY];
                    layer.open({
                        type: 2,
                        title: "用户设置",
                        shade: 0.1,
                        maxmin: true,
                        area: [common.isModile()?"100%":"720px", common.isModile()?"100%":"450px"],
                        content: UPDATE_URL + "?" + PRIMARY_KEY + "=" + value
                    });
                }

                // 表格编辑数据
                let works = function(obj) {
                    let value = obj.data['user_sn'];
                    layer.open({
                        type: 2,
                        title: "我的作品",
                        shade: 0.1,
                        maxmin: true,
                        area: [common.isModile()?"100%":"95%", common.isModile()?"100%":"95%"],
                        content: WORKS_URL + "?user_sn=" + value
                    });
                }

                // 刷新表格数据
                window.refreshTable = function(param) {
                    table.reloadData("data-table", {
                        scrollPos: "fixed"
                    });
                }

                window.flow = function (usersn,type) {
                    layer.open({
                        type: 2,
                        title: "流水明细",
                        shade: 0.1,
                        maxmin: true,
                        area: [common.isModile()?"100%":"80%", common.isModile()?"100%":"85%"],
                        content: FLOW_URL + "?" + "user_sn=" + usersn+"&type="+type
                    });
                }
            })

        </script>
    </body>
</html>
